﻿using AutoMapper;
using BS.Infra;
using BS.Infra.Interface;
using BS.Write.Api.Handler.BreedingEnterprisesn;
using MediatR;

namespace BS.Read.Api.Handler.BreedEnterprise
{
    public class ShowBreedingEnterHandler : IRequestHandler<GetBreedingEnterprisesListRequestDTO, ApiResult>
    {
        private readonly IBreedingEnterprisesRepository _breedingEnterprisesRepository;

        private readonly ILogger<ShowBreedingEnterHandler> _logger;

        private readonly IMapper _mapper;

        public ShowBreedingEnterHandler(IBreedingEnterprisesRepository breedingEnterprisesRepository,
            ILogger<ShowBreedingEnterHandler> logger, IMapper mapper)
        {
            _breedingEnterprisesRepository = breedingEnterprisesRepository;
            _logger = logger;
            _mapper = mapper;
        }
        public async Task<ApiResult> Handle(GetBreedingEnterprisesListRequestDTO request, CancellationToken cancellationToken)
        {
            try
            {
                var breedEnterprises=await _breedingEnterprisesRepository.GetAllAsync(x=>x.IsDeleted==false);
                return ApiResult.Ok(data: breedEnterprises);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "ShowBreedingEnterHandler");
                throw;
            }
        }
    }
}
public class GetBreedingEnterprisesListRequestDTO:IRequest<ApiResult>
{

}
public class GetBreedingEnterprisesListReponseDTO
{
    public int EnterpriseId { get; set; }
    /// <summary>
    /// 养殖场
    /// </summary>
    public string Farm { get; set; } = string.Empty;
    /// <summary>
    /// 负责人
    /// </summary>
    public string Principal { get; set; } = string.Empty;
    /// <summary>
    /// 存栏数量
    /// </summary>
    public int BreedingStock { get; set; }
    /// <summary>
    /// 养殖信息ID
    /// </summary>
    public int BreedingId { get; set; }
}